<?php

class AdplaceTypeAction extends CommonAction {

    // 查询数据
    public function index() {
        $this->display();
    }
	
	 public function indexjson() {
        $AdplaceType = M("AdplaceType");
        $list = $AdplaceType->limit(3)->order('id desc')->select();
		$i = 0;
		foreach($list AS $row ){
			$adplacetype[$i]['table_id'] = $row['id'];
			$adplacetype[$i]['table_name'] = $row['name'];
			$adplacetype[$i]['table_info'] = $row['info'];
			$adplacetype[$i]['table_status'] = $row['status'];
			$adplacetype[$i]['table_sort']= $row['sort'];
			 
		
		$i++;
		}
		
        echo json_encode($adplacetype);
        
    }

    // 写入数据
    public function add() {
        $AdplaceType = D("AdplaceType");
        if ($vo = $AdplaceType->create()) {
            $list = $AdplaceType->add();
            if ($list !== false) {
                $this->success('数据保存成功！');
            } else {
                $this->error('数据写入错误！');
            }
        } else {
            $this->error( $AdplaceType->getError() );
        }
    }

    // 更新数据
    public function edit() {
        $AdplaceType = D("AdplaceType");
        if ($vo = $AdplaceType->create()) {
            $list = $AdplaceType->save();
            if ($list !== false) {
                $this->success('数据更新成功！');
            } else {
                $this->error("没有更新任何数据!");
            }
        } else {
            $this->error($AdplaceType->getError());
        }
    }

    // 删除数据
    public function remove() {
		$id = intval( $_POST['form_id'] );
        if (!empty($id)) {
            $AdplaceType = M("AdplaceType");
			$vo = $AdplaceType->where("id='{$id}'")->find();
			if( $vo ) {
				$result = $AdplaceType->delete( $id );
				if (false !== $result) {
					$this->success('删除成功！');
				} else {
					$this->error('删除出错！');
				}
			}else {
				$this->error('ID错误！');
			}
            
        } else {
            $this->error('ID错误！');
        }
    }
}
?>